package com.thinkgem.jeesite.modules.sys.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.modules.sys.dao.TbMpWalletStreamJYYMapper;
import com.thinkgem.jeesite.modules.sys.entity.TbMpWalletStreamJYY;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by jyy on 2016/10/22 0022.
 */
@Service
@Transactional(readOnly = true)
public class TbMpWalletStreamJYYService {

    @Autowired
    private TbMpWalletStreamJYYMapper tbMpWalletStreamJYYMapper;

    // 用户充值列表
    public Page<TbMpWalletStreamJYY> findUserRechargeByPage(Page<TbMpWalletStreamJYY> tbMpWalletStreamJYYPage, TbMpWalletStreamJYY tbMpWalletStreamJYY) {

        // 设置默认时间范围，默认当前月
        /*if (tbMpWalletStreamJYY.getBeginDate() == null || "".equals(tbMpWalletStreamJYY.getBeginDate())){
            tbMpWalletStreamJYY.setBeginDate(DateUtils.formatDate(DateUtils.setDays(DateUtils.parseDate(DateUtils.getDate()), 1)));
        }
        if (tbMpWalletStreamJYY.getEndDate() == null || "".equals(tbMpWalletStreamJYY.getEndDate())){
            tbMpWalletStreamJYY.setEndDate(DateUtils.formatDate(DateUtils.addMonths(DateUtils.parseDate(tbMpWalletStreamJYY.getBeginDate()), 1)));
        }*/

/*

        // 设置默认时间范围，默认当前月
        if (tbMpWalletStreamJYY.getBeginDate() == null ){
            tbMpWalletStreamJYY.setBeginDate(DateUtils.setDays(DateUtils.parseDate(DateUtils.getDate()), 1));
        }
        if (tbMpWalletStreamJYY.getEndDate() == null){
            tbMpWalletStreamJYY.setEndDate(DateUtils.addMonths(tbMpWalletStreamJYY.getBeginDate(), 1));
        }
*/
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        try{
            if(tbMpWalletStreamJYY.getEndDate()!=null&&!"".equals(tbMpWalletStreamJYY.getEndDate())){
                Date date=sdf.parse(tbMpWalletStreamJYY.getEndDate());
                if(date!=null){
                    date.setHours(23);
                    date.setMinutes(59);
                    date.setSeconds(59);
                }
            }
        }catch (Exception e){

        }



        tbMpWalletStreamJYY.setPage(tbMpWalletStreamJYYPage);
        List list = tbMpWalletStreamJYYMapper.findByPage(tbMpWalletStreamJYY);
        tbMpWalletStreamJYYPage.setList(list);
        return tbMpWalletStreamJYYPage;
    }


    // 店铺充值列表
    public Page<TbMpWalletStreamJYY> findShopRechargeByPage(Page<TbMpWalletStreamJYY> tbMpWalletStreamJYYPage, TbMpWalletStreamJYY tbMpWalletStreamJYY) {

        // 设置默认时间范围，默认当前月
      /*  if (tbMpWalletStreamJYY.getBeginDate() == null || "".equals(tbMpWalletStreamJYY.getBeginDate())){
            tbMpWalletStreamJYY.setBeginDate(DateUtils.formatDate(DateUtils.setDays(DateUtils.parseDate(DateUtils.getDate()), 1)));
        }
        if (tbMpWalletStreamJYY.getEndDate() == null || "".equals(tbMpWalletStreamJYY.getEndDate())){
            tbMpWalletStreamJYY.setEndDate(DateUtils.formatDate(DateUtils.addMonths(DateUtils.parseDate(tbMpWalletStreamJYY.getBeginDate()), 1)));
        }*/

        tbMpWalletStreamJYY.setPage(tbMpWalletStreamJYYPage);
        List list = tbMpWalletStreamJYYMapper.findShopByPage(tbMpWalletStreamJYY);
        tbMpWalletStreamJYYPage.setList(list);
        return tbMpWalletStreamJYYPage;
    }
}
